// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require(CONFIG.BasePath + "js/enterprise/base");
	var router = require("../hash/pageRouter");
	var constant = require("constant");
	var css_detail = require("./accountDetailProcess.css");
	var html_signed_detail_information = require("./html_signed_detail_information.html");
	var databind = require("databind");
	var dialog = require("dialog");
	var css_dialog = require("css_dialog");
	var tools = require("tools");
	var financeId;
	var fileName;
	var financingDetail_relieve = require("./financingDetail_relieve.html");
	var html_finance_contract = require("./html_finance_contract.html");
	var html_supervision_contract = require("./html_supervision_contract.html");
	var html_supervision_inform = require("./html_supervision_inform.html");
	var html_receive_notice = require("./html_receive_notice.html");
	var html_tallying_detail = require("./html_tallying_detail.html");
	var html_supervision_confirmation = require("./html_supervision_confirmation.html");
	var html_loan_notice = require("./html_loan_notice.html");
	var html_inventory_detail = require("./html_inventory_detail.html");
	var html_normal_pickup = require("./html_normal_pickup.html");
	var html_dynamic_receivables_detail = require("./html_dynamic_receivables_detail.html");
	var html_delivery_detail = require("./html_delivery_detail.html");
	var html_finance_audit_detail = require("./html_finance_audit_detail.html");
	var html_supervision_endall = require("./html_supervision_endall.html"); 
	var html_cancelApplication = require("./html_cancelApplication.html");
	var html_verify = require("../apply/apply_verify.html");
	var html_bailReturn = require("./html_bailReturn.html");
	var type;
    var productType;
	var enterpriseId;
	var financeNumber;
	var enterpriseName;
	var financeState;
	
	var init = function(page) {
		financeId = page.params.financeId;
		type = page.params.type;
		//  	financeId = 405;
		$(".d2 a").removeClass("active_tab");
		$(".accountProcess").addClass("active_tab");
		$(".accountDetail").parent().parent().addClass("active_tab2");
		$(".accountDetail").parent().parent().removeClass("active_tab3");
		$(".accountDetail").parent().parent().removeClass("active_tab1");
		$(".accountDetail").parent().parent().removeClass("active_tab4");
		inquireFinanceProcessList();
		inquireFinanceApplicationDetail();
		router.init();
		initEvent();
	};

	var initEvent = function() {
		if (base.getData("sid") == null) {
			location.href = "../login/login.html";
		}

		$(".accountDetail").unbind("click").click(function() {
			router.route("account/accountDetail.html?financeId=" + financeId + "&type="+type);
		});

		$(".accountMaterial").unbind("click").click(function() {
			router.route("account/accountDetailMaterial.html?financeId=" + financeId + "&type="+type);
		});
		//提货列表
		$(".warehousePickups").unbind("click").click(function() {
			router.route("account/warehousePickupList2.html?financeId=" + financeId + "&type="+type);
		});
	};
	//提交融资申请
	var submitFinanceApplication = function() {
		base.fnAjax({
			action: "submitFinanceApplication.json",
			async: false,
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					router.route("account/accountMain.html");
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};
	
	//取消融资申请
	var cancelFinanceApplication = function() {
		base.fnAjax({
			action: "cancelFinanceApplication.json",
			async: false,
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					base.alert(1, "操作成功！");
					dialog.hideDialog($("#applyVerify"));
					router.route("account/accountMain.html");
				} else {
					base.alert(3, data.message);
				}
			}
		});
	};
	//查询评价信息
	var inquireFinanceEvaluate = function() {
		base.fnAjax({
			action: "inquireFinanceEvaluate.json",
			async: false,
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					if (data.datas[0].content == "") {
						$(".buttonOperate").html("评价").attr("id", "evalute");
					} else {
						$(".buttonOperate").remove();
					}
				} else {
					$(".buttonOperate").html("评价").attr("id", "evalute");
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};
	//货物一览
	var bulkstockListing = function() {
		router.route("account/accountBulkstockListing.html?financeId=" + financeId + "&productType=" + productType);
	}
	//融资评价
	var evaluteFinanceApplication = function() {
		router.route("account/accountEvaluate.html?financeId=" + financeId);
	}
	//合同一览
	var documentSign = function() {
		router.route("account/documentSign.html?financeId=" + financeId+"&financeState="+financeState);
	}
	var showEvaluteDetail = function(){
		router.route("account/accountEvaluateDetail.html?financeId="+financeId);
	}
	//额度处理
	var verifyFinanceApplication = function() {
		$("#popdialog").html(html_verify);
		dialog.showDialog($("#applyVerify"));
		$(".financeNumber").html(financeNumber);
		$(".financeAmount").html("￥" + financeAmount);

		databind.fillInput($("#applyVerify"), {
			action: "inquireCurrentEnterpriseDetail.json",
			version: "v1.0"
		});
		$("#verifySure").unbind("click").click(function() {
			consentFinanceAuditAmountApplication();
		});

		$("#verifyCancel").unbind("click").click(function() {
			cancelFinanceApplication();
		});
	}

	//接受融资审批金额
	var consentFinanceAuditAmountApplication = function() {
		base.fnAjax({
			action: "consentFinanceAuditAmountApplication.json",
			async: false,
			oData: {
				financeId: financeId
			},
			fnSuccess: function(data) {
				tools.cancelProtectDoubleClick();
				if (data.status == 200) {
					base.alert(1, "操作成功！");
					dialog.hideDialog($("#applyVerify"));
					router.route("account/accountMain.html");
				} else {
					base.alert(2, "数据获取失败");
				}
			}
		});
	};
	
	//取消融资申请
	var cancelFinanceApplication = function() {
		base.fnAjax({
			action: "cancelFinanceApplication.json",
			async: false,
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					base.alert(1, "操作成功！");
					dialog.hideDialog($("#applyVerify"));
					router.route("account/accountMain.html");
				} else {
					base.alert(3, data.message);
				}
			}
		});
	};
	//提货申请
	var pickupFinanceApplication = function() {
		router.route("account/accountPickup.html?financeId=" + financeId + "&financeNumber=" + financeNumber);
	}
	//修改融资申请
	var updateFinanceApplication = function() {
		location.href = "../apply/apply_main.html?financeId=" + financeId + "&productType=" + productType;
	}
	
	var showNotice = function(businessType, businessId, v) {
		if (businessType == 1) {
			inquireSupervisionEndall(businessId);
		} else if (businessType == 2) {
//			inquireFinanceAuditDetail(businessId);
		} else if (businessType == 3) {
			inquireFinanceContractDetail(businessId);
		} else if (businessType == 4) {
			inquireSupervisionContractDetail(businessId);
		} else if (businessType == 5) {
			inquireSupervisionNoticeDetail(businessId);
		} else if (businessType == 6) {
			inquireRecieveNoticeDetail(businessId);
		} else if (businessType == 7) {
			inquireTallyingDetail(businessId);
		} else if (businessType == 8) {
			inquireLoanNoticeDetail(businessId);
		} else if (businessType == 9) {

		} else if (businessType == 10) {
//			inquireNormalPickupApplicationDetail(businessId);
			router.route("account/accountPickupDetail.html?pickupId=" + businessId);
		} else if (businessType == 11) {
			inquireReceivablesNoticeDetail(businessId);
		} else if (businessType == 12) {
			router.route("account/inquireLogisticsInfoDetail1.html?inventoryId="+businessId);
		} else if (businessType == 13) {
			inquireDeliveryDetail(businessId);
		} else if (businessType == 14) {

		} else if (businessType == 15) {
			inquireBulkstockInventoryDetail(businessId);
			if (v == "《签收单》") {
				inquireBulkstockInventoryDetail1(businessId);
			} else {
				inquireBulkstockInventoryDetail(businessId);
			}
		} else if (businessType == 16) {
			inquireSupervisionConfirmationDetail(businessId);
		}else if (businessType == 17) {
			inquireRelieveSupervisionDetail(businessId);
		}  else {

		}
	};
	
	//监管解除通知
	var inquireRelieveSupervisionDetail = function(inventoryId) {
		base.fnAjax({
			action: "inquireBulkstockInventoryDetail.json",
			async: false,
			oData: {
				inventoryId: inventoryId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					$("#popdialog").html(financingDetail_relieve);
					dialog.showDialog($("#relieve_dialog"));
					databind.fillForm($("#relieve_dialog"), data.datas[0]);
					var tpl = $("#bulkstockInventoryListTpl").html();
					var html = juicer(tpl, data);
					$(".bulkstockInventoryBody").html(html);
					databind.disableInput($("#relieve_dialog"));
					$("#relieve_dialog .dialogHandlerBtn").unbind("click").click(function(){
						dialog.hideDialog($("#relieve_dialog"));
					});
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	};
	
	//质押终结通知--1
	var inquireSupervisionEndall = function(financeId) {
		$("#popdialog").html(html_supervision_endall);
		dialog.showDialog($("#supervision_endall_dialog"));
		base.fnAjax({
			action: "inquireSupervisionEndall.json",
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					var tpl = $("#supervision_endall_dialog .tpl").html();
					var html = juicer(tpl, data);
					$("#supervision_endall_dialog .dialogContent").html(html);
					databind.disableInput($("#supervision_endall_dialog"));
				} else {
					base.alert(3, data.message);
				}
			}
		});
		$("#supervision_endall_dialog").on("click", ".sure_yes", function() {
			dialog.hideDialog($("#supervision_endall_dialog"));
		});
	};
//	//融资审核单--2
//	var inquireFinanceAuditDetail = function(financeAuditId){
//		$("#popdialog").html(html_finance_audit_detail);
//		dialog.showDialog($("#finance_audit_detail_dialog"));
//		base.fnAjax({
//			action: "inquireFinanceAuditDetail.json",
//			oData: {
//				financeAuditId: financeAuditId
//			}, //传递参数
//			fnSuccess: function(data) { //成功回调
//				if (data.status == 200) {
//					juicer.register("getValueByKey", constant.getValueByKey);
//					var tpl = $("#finance_audit_detail_dialog .tpl").html();
//					var html = juicer(tpl, data);
//					$("#finance_audit_detail_dialog .dialogContent").html(html);
//					databind.disableInput($("#finance_audit_detail_dialog"));
//					var materialsId = $("#materials input").val();
//					showImg("#showImg", materialsId);
//					$("#finance_audit_detail_dialog .sure_yes").unbind("click").click(function(){
//						dialog.hideDialog($("#finance_audit_detail_dialog"));
//					});
//					
//					$.each($("#finance_audit_detail_dialog .field-textarea3"), function() {
//						var $this = $(this);
//						if ($.trim($this.html()) == "") {
//							$this.parent().find("span").html("未审核");
//						}
//					});	
//				} else {
//					base.alert(3, data.message);
//				}
//			}
//		});
//	}
	//显示图片
	var showImg = function(dom, fileUuid) {
		if (fileUuid.length == 0) {
			return;
		}
		var fileUuids = fileUuid.split(",");
		var html = "";
		var imgSrc = "";
		for (var i = 0; i < fileUuids.length; i++) {
			imgSrc = fileUuids[i];
			var fileName = tools.inquireFile(imgSrc);
			if (imgSrc.length != 0) {
				html = '<a target="_Blank" href="/finance/api/1.0/downloadFile.file?fileUuid=' + imgSrc + '">';
				html += '<div class="finance-file" id="' + imgSrc + '">';
				html += '<img  src="../../../res/png/file_icon.png" class="finance-field-img"  alt="' + imgSrc + '" />';
				html += '<div class="fileName" style="text-align:center;">'+ fileName +'</div></div></a>';

				$(dom).append(html);
			}

		}
	}
	//配送单-13
	var inquireDeliveryDetail = function(deliveryId){
		$("#popdialog").html(html_delivery_detail);
		dialog.showDialog($("#delivery_detail_dialog"));
		base.fnAjax({
			action: "inquireDeliveryDetail.json",
			oData: {
				deliveryId: deliveryId
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $("#delivery_detail_dialog .tpl").html();
					var html = juicer(tpl, data);
					$("#delivery_detail_dialog .dialogContent").html(html);
					databind.disableInput($("#delivery_detail_dialog"));
					$("#delivery_detail_dialog .sure_yes").unbind("click").click(function(){
						dialog.hideDialog($("#delivery_detail_dialog"));
					});
				} else {
					base.alert(3, data.message);
				}
			}
		});
	}
	//放款通知-10
	var inquireNormalPickupApplicationDetail = function(pickupId) {
		$("#popdialog").html(html_normal_pickup);
		dialog.showDialog($("#normal_pickup_dialog"));
		base.fnAjax({
			action: "inquireNormalPickupApplicationDetail.json",
			oData: {
				pickupId: pickupId
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $("#normal_pickup_dialog .tpl").html();
					var html = juicer(tpl, data);
					$("#normal_pickup_dialog .dialogContent").html(html);
					databind.disableInput($("#normal_pickup_dialog"));
					$("#normal_pickup_dialog .sure_yes").unbind("click").click(function(){
						dialog.hideDialog($("#normal_pickup_dialog"));
					});
				} else {
					base.alert(3, data.message);
				}
			}
		});
	};
	
	var inquireBulkstockInventoryDetail = function(inventoryId) {
		$("#popdialog").html(html_inventory_detail);
		dialog.showDialog($("#inventory_detail_dialog"));
		base.fnAjax({
			action: "inquireBulkstockInventoryDetail.json",
			oData: {
				inventoryId: inventoryId
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $("#inventory_detail_dialog .tpl").html();
					var html = juicer(tpl, data);
					$("#inventory_detail_dialog .dialogContent").html(html);
					databind.disableInput($("#inventory_detail_dialog"));
					$("#inventory_detail_dialog .sure_yes").unbind("click").click(function(){
						dialog.hideDialog($("#inventory_detail_dialog"));
					});
				} else {
					base.alert(3, data.message);
				}
			}
		});
	};
	
	var inquireBulkstockInventoryDetail1 = function(inventoryId) {
		base.fnAjax({
			action: "inquireBulkstockInventoryDetail.json",
			async: false,
			oData: {
				inventoryId: inventoryId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					$("#popdialog").html(html_signed_detail_information);
					var tpl = $("#sigendDetailTpl").html();
					var html = juicer(tpl, data);
					$("#sigendDetailBody").html(html);
					var signPreFile = data.datas[0].signPreFile.split(',');
					var signSuffixFile = data.datas[0].signSuffixFile.split(',');
					$.each(signPreFile, function() {
						$("#signed_detail_dialog .signPreFile").append("<a target='_blank' href='/finance/api/v1.0/downloadFile.file?fileUuid=" + this + " '><img src='/finance/api/v1.0/downloadFile.file?fileUuid=" + this + " '/></a>")
					});
					$.each(signSuffixFile, function() {
						$("#signed_detail_dialog .signSuffixFile").append("<a target='_blank' href='/finance/api/v1.0/downloadFile.file?fileUuid=" + this + " '><img src='/finance/api/v1.0/downloadFile.file?fileUuid=" + this + " '/></a>")
					});
					
					tools.showLogisticsTrajectory(data.datas[0].caseNumber, data.datas[0].waybillNumber, $("#signed_detail_dialog .logisticsDetailInfo"));
					
					dialog.showDialog($("#signed_detail_dialog"));
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	};
	
	
	var inquireLoanNoticeDetail = function(loanNoticeId) {
		$("#popdialog").html(html_loan_notice);
		dialog.showDialog($("#loan_notice_dialog"));
		base.fnAjax({
			action: "inquireLoanNoticeDetail.json",
			oData: {
				loanNoticeId: loanNoticeId
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $("#loan_notice_dialog .tpl").html();
					var html = juicer(tpl, data);
					$("#loan_notice_dialog .dialogContent").html(html);
					databind.disableInput($("#loan_notice_dialog"));
					$("#loan_notice_dialog .sure_yes").unbind("click").click(function(){
						dialog.hideDialog($("#loan_notice_dialog"));
					});
				} else {
					base.alert(3, data.message);
				}
			}
		});
	};
	
	//监管确认书-16
	var inquireSupervisionConfirmationDetail = function(confirmationId) {
		$("#popdialog").html(html_supervision_confirmation);
		dialog.showDialog($("#supervision_confirmation_dialog"));
		base.fnAjax({
			action: "inquireSupervisionConfirmationDetail.json",
			version: "v1.0",
			async: false,
			oData: {
				confirmationId: confirmationId
			}, //传递参数
			fnSuccess: function(data) { //成功回调
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $("#supervision_confirmation_dialog .tpl").html();
					var html = juicer(tpl, data);
					html += inquireFinanceApplicationDetail();
					$("#supervision_confirmation_dialog .dialogContent").html(html);
					databind.disableInput($("#supervision_confirmation_dialog"));
					$("#supervision_confirmation_dialog .sure_yes").unbind("click").click(function(){
						dialog.hideDialog($("#supervision_confirmation_dialog"));
					});
				} else {
					base.alert(3, data.message);
				}
			}
		});
	};
	
	//监管通知-5
	var inquireSupervisionNoticeDetail = function(supervisionNoticeId){
		$("#popdialog").html(html_supervision_inform);
		dialog.showDialog($("#supervision_inform_dialog"));
		databind.fillInput($("#supervision_inform_dialog"), {
			action: "inquireSupervisionNoticeDetail.json?supervisionNoticeId=" + supervisionNoticeId,
			version: "v1.0",
			async: false
		});
		databind.disableInput($("#supervision_inform_dialog"));
		$("#supervision_inform_dialog").on("click", ".sure_yes", function(){
			dialog.hideDialog($("#supervision_inform_dialog"));
		});
	}

	//收款通知书-11
	var inquireReceivablesNoticeDetail = function(receivablesId) {
		$("#popdialog").html(html_dynamic_receivables_detail);
		dialog.showDialog($("#dynamic_receivable_detail_dialog"));

		databind.fillInput($("#dynamic_receivable_detail_dialog"), {
			action: "inquireReceivablesDetail.json?receivablesId=" + receivablesId,
			version: "v1.0",
			async: false
		});
		$("#dynamic_receivable_detail_dialog .fileUuids").parent().find("a").attr("href", "/finance/api/v1.0/downloadFile.file?fileUuid="+$("#dynamic_receivable_detail_dialog .fileUuids").val());
		var beneficiaryMethod = $("#dynamic_receivable_detail_dialog .beneficiaryMethod").val();
		switch (parseInt(beneficiaryMethod)){
			case 1:
				$("#dynamic_receivable_detail_dialog .beneficiaryMethod").val("现金");
				break;
			case 2:
				$("#dynamic_receivable_detail_dialog .beneficiaryMethod").val("支票");
				break;
			case 3:
				$("#dynamic_receivable_detail_dialog .beneficiaryMethod").val("转账");
				break;
			default:
				break;
		}
		databind.disableInput($("#dynamic_receivable_detail_dialog"));
		$("#dynamic_receivable_detail_dialog").on("click", ".sure_yes", function(){
			dialog.hideDialog($("#dynamic_receivable_detail_dialog"));
		});
	};

	//融资合同-3
	var inquireFinanceContractDetail = function(financeContractId) {
		$("#popdialog").html(html_finance_contract);
		dialog.showDialog($("#finance_contract_dialog"));
		databind.fillInput($("#finance_contract_dialog"), {
			action: "inquireFinanceContractDetail.json?financeContractId=" + financeContractId,
			version: "v1.0",
			async: false
		});
		databind.disableInput($("#finance_contract_dialog"));
		$("#finance_contract_dialog").on("click", ".sure_yes", function(){
			dialog.hideDialog($("#finance_contract_dialog"));
		});
		var ms = $("#finance_contract_dialog .materials").val().split(',');
		$.each(ms, function() {
			var str = "<a target='_blank' class='showFiles' href='/finance/api/v1.0/downloadFile.file?fileUuid="+ this +"'>"+tools.inquireFile(this)+"</a>";
			$("#finance_contract_dialog .materials").parent().append(str);
		});
	};

	//监管合同-4
	var inquireSupervisionContractDetail = function(supervisionContractId) {
		$("#popdialog").html(html_supervision_contract);
		dialog.showDialog($("#supervision_contract_dialog"));
		databind.fillInput($("#supervision_contract_dialog"), {
			action: "inquireSupervisionContractDetail.json?supervisionContractId=" + supervisionContractId,
			version: "v1.0",
			async: false
		});
		databind.disableInput($("#supervision_contract_dialog"));
		$("#supervision_contract_dialog").on("click", ".sure_yes", function(){
			dialog.hideDialog($("#supervision_contract_dialog"));
		});
		var ms = $("#supervision_contract_dialog .materials").val().split(',');
		$.each(ms, function() {
			var str = "<a target='_blank' class='showFiles' href='/finance/api/v1.0/downloadFile.file?fileUuid="+ this +"'>"+tools.inquireFile(this)+"</a>";
			$("#supervision_contract_dialog .materials").parent().append(str);
		});
	};
	
	
	//查询放货通知-6
	var inquireRecieveNoticeDetail = function(recieveNoticeId) {
		$("#popdialog").html(html_receive_notice);
		dialog.showDialog($("#receive_notice_dialog"));
		base.fnAjax({
			action: "inquireRecieveNoticeDetail.json",
			async: false,
			oData: {
				recieveNoticeId: recieveNoticeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $("#receive_notice_dialog .tpl").html();
					var html = juicer(tpl, data);
					$("#receive_notice_dialog .dialogContent").html(html);
					databind.disableInput($("#receive_notice_dialog"));
					$("#receive_notice_dialog .sure_yes").unbind("click").click(function(){
						dialog.hideDialog($("#receive_notice_dialog"));
					});
				} else {
					base.alert(2, data.message);
				}
			}
		});
	};

	//查询理货清单-7
	var inquireTallyingDetail = function(tallyingId) {
		router.route("account/tallyingDetail.html?tallyingId=" + tallyingId);
//		$("#popdialog").html(html_tallying_detail);
//		dialog.showDialog($("#tallying_detail_dialog"));
//		base.fnAjax({
//			action: "inquireTallyingDetail.json",
//			async: false,
//			oData: {
//				tallyingId: tallyingId
//			}, //传递参数
//			fnSuccess: function(data) {
//				if (data.status == 200) {
//					var tpl = $("#tallying_detail_dialog .tpl").html();
//					var html = juicer(tpl, data);
//					$("#tallying_detail_dialog .dialogContent").html(html);
//					databind.disableInput($("#tallying_detail_dialog"));
//					if(data.datas[0]==0){
//						$(".withCar").html('<option value="0">否</option>');
//					}else{
//						$(".withCar").html('<option value="1">是</option>');
//					}
//					
//					$("#tallying_detail_dialog .sure_yes").unbind("click").click(function(){
//						dialog.hideDialog($("#tallying_detail_dialog"));
//					});
//				} else {
//					base.alert(2, "信息获取失败");
//				}
//			}
//		});
	};

	//企业查询融资动态
	var inquireFinanceProcessList = function() {
		base.fnAjax({
			action: "inquireFinanceProcessList.json",
			async: false,
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $("#accountProcessTpl").html();
					var html = juicer(tpl, data);
//                	financeNumber = data.datas[0].financeNumber;
					$("#accountProcessBody").html(html);
					if ($(".div1 div").html() == null) {
						$(".div1").append('<p class="div11"><span class="span1">未开始</span><span class="span2"></span><span class="span3"></span><span class="span4"></span></p>');
					}
					if ($(".div2 div").html() == null) {
						$(".div2").append('<p class="div11"><span class="span1">未开始</span><span class="span2"></span><span class="span3"></span><span class="span4"></span></p>');
					}
					if ($(".div3 div").html() == null) {
						$(".div3").append('<p class="div11"><span class="span1">未开始</span><span class="span2"></span><span class="span3"></span><span class="span4"></span></p>');
					}
					if ($(".div4 div").html() == null) {
						$(".div4").append('<p class="div11"><span class="span1">未开始</span><span class="span2"></span><span class="span3"></span><span class="span4"></span></p>');
					}
					changeProcessColor();
					$(".pickup").unbind("click").click(function() {
						if ($(this).parent().parent().next(".logistics_info2").css('display') == 'none') {
							$(this).parent().parent().next(".logistics_info2").css('display', 'block');
							$(this).html('收起<img src="../../../res/png/arrow8_icon.png">');
						} else if ($(this).parent().parent().next(".logistics_info2").css('display') == 'block') {
							$(this).parent().parent().next().css('display', 'none');
							$(this).html('展开<img src="../../../res/png/arrow1_icon.png">');
						}
					});
					$(".businessVoucher").unbind("click").click(function() {
						showNotice($(this).attr("businessType"), $(this).attr("businessId"),  $(this).html());
					});

				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};
	
	//企业查询融资动态
	var inquireFinanceApplicationDetail = function() {
		var html = "";
		base.fnAjax({
			action: "inquireFinanceApplicationDetail.json",
			async: false,
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $("#bookingSpaceTpl").html();
//					html = juicer(tpl, data);
					productType = data.datas[0].productType;
                	enterpriseId = data.datas[0].enterpriseId;
                	financeNumber = data.datas[0].financeNumber;
                	enterpriseName = data.datas[0].enterpriseName;
                	financeState = data.datas[0].financeState;
					if(productType == 2){
						if (financeState == 1) {
							
						} else if (financeState == 2) {
							$(".buttonOperate4").html("额度处理").attr("id", "verifyApply3").removeClass("none");
							$(".buttonOperate4:first").before('<a class="buttonOperate4" id="cancelApply3">取消申请</a>');
						} else if (financeState == 4) {
							$(".buttonOperate4").html("修改").attr("id", "modifyApply3").removeClass("none");
							$(".buttonOperate4:first").before('<a class="buttonOperate4" id="cancelApply3">取消申请</a>');
						} else if (financeState == 17) {
							inquireFinanceEvaluate();
						} else if (financeState == 18) {
							$(".buttonOperate4").html("评价").attr("id", "evalute3").removeClass("none");
						} else if (financeState == 19) {
							$(".buttonOperate4").html("评价信息").attr("id", "evaluteDetail3").removeClass("none");
						} else if (financeState == 20) {
							$(".buttonOperate4").html("取消申请").attr("id", "cancelApply3").removeClass("none");
							$(".buttonOperate4:first").before('<a class="buttonOperate4" id="modifyApply3">修改</a>');
							$(".buttonOperate4:first").before('<a class="buttonOperate4" id="submitApply3">提交融资</a>');
						} else {
							$(".buttonOperate4").hide();
						}
						
						if (data.datas[0].bail - data.datas[0].bailAlreadyReturn > 0) {
							$(".buttonOperate4:first").before('<a class="buttonOperate4" id="bailReturn3">退还保证金</a>');
						}
						if (financeState > 5) {
							$(".buttonOperate4:first").before('<a class="buttonOperate4" id="bulkstockListing3">货物一览</a>');
						}
						if (financeState == 24 || financeState == 23 || financeState == 22) {
							$(".buttonOperate4:first").before('<a class="buttonOperate4" id="documentSign3">合同签署</a>');
						}
	
						if (financeState >= 6) {
							$(".exceptionOperate").removeClass("none");
							$(".buttonOperate4:first").before('<a class="buttonOperate4" id="pickupApply3">申请提货</a>');
						}
					}else if(productType == 6){
						if (data.datas[0].bail - data.datas[0].bailAlreadyReturn > 0) {
							$(".buttonOperate4:first").before('<a class="buttonOperate4" id="bailReturn3">退还保证金</a>');
						}
						if (financeState > 5) {
							$(".buttonOperate4:first").before('<a class="buttonOperate4" id="bulkstockListing3">货物一览</a>');
						}
						if (financeState == 24 || financeState == 23 || financeState == 22) {
							$(".buttonOperate4:first").before('<a class="buttonOperate4" id="documentSign3">合同签署</a>');
						}
	
						$(".buttonOperate4:first").before('<a class="buttonOperate4" id="createPickup11s3">提货</a>');
					}else if(productType == 5){
						if (financeState > 5) {
							$(".buttonOperate4:first").before('<a class="buttonOperate4" id="bulkstockListing3">货物一览</a>');
						}
						if (financeState == 24 || financeState == 23 || financeState == 22) {
							$(".buttonOperate4:first").before('<a class="buttonOperate4" id="documentSign3">合同签署</a>');
						}
	
						$(".buttonOperate4:first").before('<a class="buttonOperate4" id="createPickup11s3">提货</a>');
					}
					
					$(".buttonOperate4:first").before('<a class="buttonOperate4" id="calcelApply3">融资申请取消</a>');
					
					databind.disableInput(".content2");
					$("#calcelApply3").unbind("click").click(function(){
						var ii = layer.open({
						  title: '融资取消申请',
						  type: 1,
						  skin: 'layui-layer-rim', //加上边框
						  area: ['800px', '300px'], //宽高
						  content: html_cancelApplication,
						  btn: ['确定', '取消'],
						  yes: function(){
						  	databind.submitDom($(".createFinanceCancelApplication"), function(){
						  		layer.msg("申请成功！");
						  		layer.close(ii);
						  		router.route("account/accountDetail.html?financeId=" + financeId);
						  	});
						  }
						});
						
						$(".createFinanceCancelApplication input[name=financeId]").val(financeId);
					});
					//取消融资
					$("#cancelApply3").unbind("click").click(function() {
						dialog.showConfirmDialog("取消融资", "是否确定取消融资？", function(){
							cancelFinanceApplication();
						});
					});
					//提交融资
					$("#submitApply3").unbind("click").click(function() {
						dialog.showConfirmDialog("提交融资", "提交以后不能再次修改,是否确定提交融资？", function(){
							submitFinanceApplication();
						});
					});
					
					$("#verifyApply3").unbind("click").click(function() {
						verifyFinanceApplication();
					});
					
					//修改融资
					$("#modifyApply3").unbind("click").click(function() {
						updateFinanceApplication();
					});
					//评价
					$("#evalute3").unbind("click").click(function() {
						evaluteFinanceApplication();
					});
					//货物一览
					$("#bulkstockListing3").unbind("click").click(function() {
						bulkstockListing();
					});
					//合同一览
					$("#documentSign3").unbind("click").click(function() {
						documentSign();
					});
					//保证金退还
					$("#bailReturn3").unbind("click").click(function() {
						var ii = layer.open({
						  title: '保证金退还',
						  type: 1,
						  skin: 'layui-layer-rim', //加上边框
						  area: ['300px', '150px'], //宽高
						  content: html_bailReturn,
						  btn: ['确定', '取消'],
						  yes: function(){
						  	databind.submitDom($(".createBailReturn"), function(){
						  		layer.msg("申请成功！");
						  		layer.close(ii);
						  	});
						  }
						});
						$(".createBailReturn input[name=financeId]").val(financeId);
						tools.clearNoNumAll($(".createBailReturn"));
					});
					//提货
					$("#createPickup11s3").unbind("click").click(function(){
						if(productType == 5){
							router.route("account/createPickup6.html?enterpriseId=" + enterpriseId +"&financeNumber=" + financeNumber+"&enterpriseName="+enterpriseName+"&productType="+productType+"&financeId="+financeId);
						}else if(productType == 6){
							router.route("account/createPickup4.html?enterpriseId=" + enterpriseId +"&financeNumber=" + financeNumber+"&enterpriseName="+enterpriseName+"&productType="+productType+"&financeId="+financeId);
						}
						
					});
					//查看评价信息
					$("#evaluteDetail3").unbind("click").click(function() {
						showEvaluteDetail();
					});
					//提货申请
					$("#pickupApply3").unbind("click").click(function() {
						pickupFinanceApplication();
					});
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
		return html;
	};

	var changeProcessColor = function() {
		//融资动态颜色背景改变
		var status1 = $('#accountProcessBody').find('.div1').find('.div11').find('.span1').html();
		var status2 = $('#accountProcessBody').find('.div2').find('.div11').find('.span1').html();
		var status3 = $('#accountProcessBody').find('.div3').find('.div11').find('.span1').html();
		var status4 = $('#accountProcessBody').find('.div4').find('.div11').find('.span1').html();
		if (status4 == '未开始') {
			$('.content4').find('.tab3').find('.div4').find('img').first().attr('src', '../../../res/png/round_ed.png');
			$('.content4').find('.tab3').find('.div4').css({
				'background': 'url(../../../res/png/line_last.png) no-repeat',
				'color': '#B4B9BE'
			});
			if (status3 == '未开始') {
				$('.content4').find('.tab3').find('.div3').find('img').first().attr('src', '../../../res/png/round_ed.png');
				$('.content4').find('.tab3').find('.div3').css({
					'background': 'url(../../../res/png/line_will.png) repeat-y',
					'color': '#B4B9BE'
				});
				if (status2 == '未开始') {
					$('.content4').find('.tab3').find('.div2').find('img').first().attr('src', '../../../res/png/round_ed.png');
					$('.content4').find('.tab3').find('.div2').css({
						'background': 'url(../../../res/png/line_will.png) repeat-y',
						'color': '#B4B9BE'
					});
					if (status1 == '未开始') {
						$('.content4').find('.tab3').find('.div1').find('img').first().attr('src', '../../../res/png/round_ed.png');
						$('.content4').find('.tab3').find('.div1').css({
							'background': 'url(../../../res/png/line_will.png) repeat-y',
							'color': '#B4B9BE'
						});
					} else {
						$('.content4').find('.tab3').find('.div1').find('img').first().attr('src', "../../../res/png/round_ing.png");
						$('.content4').find('.tab3').find('.div1').css({
							'background': 'url(../../../res/png/line_ing.png) repeat-y',
							'color': '#28BF85'
						});
					}
				} else {
					$('.content4').find('.tab3').find('.div2').find('img').first().attr('src', "../../../res/png/round_ing.png");
					$('.content4').find('.tab3').find('.div2').css({
						'background': 'url(../../../res/png/line_ing.png) repeat-y',
						'color': '#28BF85',
						'padding-bottom': '17px'
					});
					$('.content4').find('.tab3').find('.div1').find('img').first().attr('src', "../../../res/png/round_ed.png");
					$('.content4').find('.tab3').find('.div1').css({
						'background': 'url(../../../res/png/line_ed.png) repeat-y',
						'color': '#878787'
					});
					$('.content4').find('.tab3').find('.div1').find('div').last().css({
						'color': '#878787',
						'border-bottom': 'solid #E3E3E3 2px',
						'padding-bottom': '17px'
					});
				}
			} else {
				$('.content4').find('.tab3').find('.div3').find('img').first().attr('src', "../../../res/png/round_ing.png");
				$('.content4').find('.tab3').find('.div3').css({
					'background': 'url(../../../res/png/line_ing.png) repeat-y',
					'color': '#28BF85',
					'padding-bottom': '17px'
				});
				$('.content4').find('.tab3').find('.div2').find('img').first().attr('src', "../../../res/png/round_ed.png");
				$('.content4').find('.tab3').find('.div2').css({
					'background': 'url(../../../res/png/line_ed.png) repeat-y',
					'color': '#878787'
				});
				$('.content4').find('.tab3').find('.div2').find('div').last().css({
					'color': '#878787',
					'border-bottom': 'solid #E3E3E3 2px',
					'padding-bottom': '17px'
				});
				$('.content4').find('.tab3').find('.div2').find('.span1').find('img').attr('src', "../../../res/png/point_ed.png");
			}
		} else {
			$('.content4').find('.tab3').find('.div4').find('img').first().attr('src', "../../../res/png/round_ing.png");
			$('.content4').find('.tab3').find('.div4').css({
				'background': 'url(../../../res/png/line_last.png) no-repeat',
				'color': '#28BF85'
			});
			$('.content4').find('.tab3').find('.div3').find('img').first().attr('src', "../../../res/png/round_ed.png");
			$('.content4').find('.tab3').find('.div3').css({
				'background': 'url(../../../res/png/line_ed.png) repeat-y',
				'color': '#878787'
			});
			$('.content4').find('.tab3').find('.div3').find('div').last().css({
				'color': '#878787',
				'border-bottom': 'solid #E3E3E3 2px',
				'padding-bottom': '17px'
			});
		}

		var divarray = $('.content4').find('.tab3').find('div').find('div');
		var flag;
		for (var i = 0, j = divarray.length; i < j; i++) {
			if ($(divarray[i]).find('.span3').html() == '' && $(divarray[i]).find('.span1').html() != '' && $(divarray[i]).find('.span2').html() == '' && $(divarray[i]).find('.span4').html() != '') {
				$(divarray[i]).find('.span1').css({
					'color': '#595959',
					'font-weight': 'bold',
					'font-size': '13px',
					'width': '535px'
				});
				$(divarray[i]).find('.span2').css({
					'width': '0'
				});
				$(divarray[i]).find('.span3').css({
					'width': '0'
				});
				$(divarray[i]).find('.span4').css({
					'color': '#595959',
					'width': '142px'
				});
				$(divarray[i]).css({
					'border-top': 'solid #E3E3E3 1px',
					'padding-top': '12px',
					'padding-bottom': '12px',
					'margin-bottom': '0'
				});
				flag = i;
			}
		}
		$(divarray[flag]).css({
			'border-bottom': 'solid #E3E3E3 1px',
			'padding-bottom': '12px'
		});

	};

	return {
		init: init
	};
});